<layout name="popup" />
<block name="content">
	<input type="hidden" name="val" id="val">
	<input type="hidden" name="name" id="name">
	<div class="popup-header">
		<h1>请选择上级节点</h1>
		<i class="mid"></i>
		<a class="btn btn-normal" onclick="save();">确定</a>
		<a class="btn btn-return" onclick="close_popup();">取消</a>
	</div>
	<div class="popup-body">
		<div class="popup-body-scroll">
			<div class="popup-content">
				<div class="tree-menu">
					<a node="0" style="padding-left:8px;width:100%;display:block;line-height: 32px;">根节点</a>
				</div>
				<div class="tree-menu">
					{:widget('html/tree_menu',array($tree))}
				</div>
			</div>
		</div>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		var index = parent.layer.getFrameIndex(window.name);

		function save() {
			if ($("#name").val().length > 0) {
				$("#node_name", parent.document).val($("#name").val());
				$("#pid", parent.document).val($("#val").val());
			} else {
				parent.layer.msg('"请选择级部门"');
				return false;
			}
			parent.layer.close(index);
		};

		function close_popup() {
			parent.layer.close(index);
		};

		layui.use(['global'], function() {
			var $ = layui.jquery;
			parent_node = $(".tree-menu a.active", parent.document).attr("node");
			$(".tree-menu a[node='" + parent_node + "']").addClass("disabled");
			$(".tree-menu a[node='" + parent_node + "'] + input + label + ul a").addClass("disabled");
			$(".tree-menu a:not('.disabled')").click(function() {
				$this = $(this);
				$("#val").val($this.attr("node"));
				$("#name").val($this.text());
				$(".tree-menu a.active").removeClass("active");
				$this.addClass("active");
			});

		});
	</script>
</block>